﻿using System.Collections.Generic;
using System.Text;

namespace Google.Translates.Core
{
    public class StringHelper
    {
        private const string splitsSentenceKeyString = "!;.。；";
        private const string splitsWordKeyString = "1234567890`-=~!@#$%^&*()_+\\][\';.,/》《：“”‘’、。，】【{}；<>:\"}{|";
        /// <summary>
        /// 斷句時所需要考慮的標點符號
        /// </summary>
        public static char[] GetSentencesSplitsKey()
        { return splitsWordKeyString.ToCharArray(); }

        public static char[] GetWordsSplitsKey()
        {
           return (splitsWordKeyString + "  ").ToCharArray();
        }


        public const string Break_Sentences_Model_Mine = "MySelf", Break_Sentences_Model_Bing = "Bing";

        public static List<string> SplitSentence(string longSentence, ref List<string> splitKeyVals)
        {
            var scShotSentence = new List<string>();
            longSentence = longSentence.Replace("\r\n", "\r");
            if (splitKeyVals == null) splitKeyVals = new List<string>();
            int pevEndIndex = -1;
            while (true)
            {
                int tempEndIndex = longSentence.IndexOfAny(GetSentencesSplitsKey(), pevEndIndex + 1);
                if (tempEndIndex > -1)
                {
                    string tranSrcVal = longSentence.Substring(pevEndIndex + 1, tempEndIndex - pevEndIndex - 1);
                    scShotSentence.Add(tranSrcVal);
                    splitKeyVals.Add(longSentence.Substring(tempEndIndex, 1));
                    pevEndIndex = tempEndIndex;
                }
                else
                {
                    if (pevEndIndex + 1 < longSentence.Length)
                    {
                        var val = longSentence.Substring(pevEndIndex + 1);
                        if(!string.IsNullOrEmpty(val))scShotSentence.Add(val);
                    }
                        
                    break;
                }
            }
            return scShotSentence;
        }

        
    }
}